package com.zkingsoft.actions.admin;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.constance.Dictionary;
import com.zkingsoft.model.Fy;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.plugin.util.WebUtil;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.FyService;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2016-10-07 08:53
 */
@Controller
@RequestMapping(value = "admin/fy")
public class FyController extends BaseController {

	@Resource
	private FyService currentService;

	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(Fy fy, PaginationVO pageVo) {
		return showList(currentService, fy, pageVo);
	}

	/**
	 * 新增或者修改页面
	 */
	@RemoveRequestToken
	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(Fy fy) {
		if (fy.getId() != null) {
			return modify(currentService, fy, "房源");
		} else {
			fy.setFySource(Dictionary.FY_RESOURCE_NBFB);
			return add(currentService, fy, "房源");
		}
	}

	/**
	 * 
	* @Description: 进入修改界面 
	* @author:姜友瑶
	* @param id
	* @param flag 1 表示修改 2表示修改审核
	* @return    
	* 返回类型  String    
	* @date 2016年10月9日
	 */
	@SaveRequestToken
	@RequestMapping(value = "/editForm")
	public String editForm(Long id, int flag) {
		Fy fy = currentService.findById(id);
		WebUtil.getRequest().setAttribute("obj", fy);
		WebUtil.getRequest().setAttribute("flag", flag);
		String path = getPath(fy);
		return "admin/" + path;
	}


	/**
	 * 进入新增界面
	 */
	@SaveRequestToken
	@RequestMapping(value = "/addForm")
	public String addForm(Long id) {
		return "admin/publish-fy";
	}

	/**
	 * 进入新增界面2
	 */
	@SaveRequestToken
	@RequestMapping(value = "/addForm2")
	public @ResponseBody AjaxResult addForm2(Fy fy) {
		WebUtil.getSession().setAttribute("obj", fy);
		String path = getPath(fy);
		return new AjaxResult(AjaxResult.STATUS_OK,  path, "正在跳转");
	}

	/**
	 * 删除
	 */
	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		return remove(currentService, keys);
	}

	/**
	 * 审核房源通过
	 */
	@RequestMapping(value = "/fyCheckPass")
	public @ResponseBody AjaxResult fyCheckPass(Long id) {
		int i = currentService.fyCheck(id);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_OK, null, "操作成功");
		} else {
			return new AjaxResult(AjaxResult.STATUS_ERR, null, "审核失败");
		}
	}

	/**
	 * 审核房源驳回
	 */
	@RequestMapping(value = "/fyCheckBh")
	public @ResponseBody AjaxResult fyCheckBh(Long id, String msg) {
		int i = currentService.fyCheckBh(id, msg);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_OK, null, "操作成功");
		} else {
			return new AjaxResult(AjaxResult.STATUS_ERR, null, "驳回失败");
		}
	}

	/**
	 * 
	* @Description: 根据房源类型跳转到不同的页面
	* @author:姜友瑶
	* @param fy
	* @return    
	* 返回类型  String    
	* @date 2016年10月9日
	 */
	private String getPath(Fy fy) {
		String path = "";
		// 二手房
		if (fy.getFyKinds().equals(Dictionary.FY_KINDS_ESF) && fy.getFyGq().equals(Dictionary.FY_GQ_CS)) {
			path = "fy-xfcsform";
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_ESF) && fy.getFyGq().equals(Dictionary.FY_GQ_QG)) {
			path = "fy-xfqgform";

			// 写字楼
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_XZL)
				&& (fy.getFyGq().equals(Dictionary.FY_GQ_QG) || fy.getFyGq().equals(Dictionary.FY_GQ_QZ))) {
			path = "fy-xzlqgform";
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_XZL)
				&& (fy.getFyGq().equals(Dictionary.FY_GQ_CS) || fy.getFyGq().equals(Dictionary.FY_GQ_CZ))) {
			path = "fy-xzlcsform";

			// 出租房
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_CZF) && fy.getFyGq().equals(Dictionary.FY_GQ_CZ)) {
			path = "fy-czfczform";
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_CZF) && fy.getFyGq().equals(Dictionary.FY_GQ_QZ)) {
			path = "fy-czfqzform";

			// 商铺
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_SP) && (fy.getFyGq().equals(Dictionary.FY_GQ_ZR)
				|| fy.getFyGq().equals(Dictionary.FY_GQ_CZ) || fy.getFyGq().equals(Dictionary.FY_GQ_CS))) {
			path = "fy-spzrform";
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_SP)
				&& (fy.getFyGq().equals(Dictionary.FY_GQ_QG) || fy.getFyGq().equals(Dictionary.FY_GQ_QZ))) {
			path = "fy-spqgform";

			// 厂房
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_CF) && (fy.getFyGq().equals(Dictionary.FY_GQ_CS)
				|| fy.getFyGq().equals(Dictionary.FY_GQ_CZ) || fy.getFyGq().equals(Dictionary.FY_GQ_ZR))) {
			path = "fy-cfcsform";
		} else if (fy.getFyKinds().equals(Dictionary.FY_KINDS_CF)
				&& (fy.getFyGq().equals(Dictionary.FY_GQ_QZ) || fy.getFyGq().equals(Dictionary.FY_GQ_QG))) {
			path = "fy-cfqgform";
		}
		return path;
	}
}